<template>
    <div id="tmpl1">
        <div class="inleft div" @click="substrict">-</div>
        <div class="incenter div" v-text="count"></div>
        <div class="inright div" @click="add">+</div>
    </div>
</template>

<script>
    export default{
        data(){
            return {
                count:1 //代表购买商品的数量
            }
        },
        methods:{
            substrict(){
                this.count--;
                // 确保最小值为1
                if(this.count < 1) {
                    this.count = 1;
                }
                this.sendmessage();
            },
            add(){
                this.count++;
                this.sendmessage();
            },
            sendmessage(){
                this.$emit('dataobj',this.count);
            }
        }
    }
</script>

<style scoped>
    #tmpl1 {
        display: inline-block;
    }
    #tmpl1 .div {
        display: inline-block;
        width: 40px;
        height: 24px;
        border:1px solid #000;
        text-align: center;
        line-height: 24px;
    }
</style>